﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Text;
using DevicesInt;

namespace _3S_Cam
{
    public class Cam : DeviceUnmanagedCall
    {
        public override DeviceControl GetController(string ip)
        {
            return new CamController(ip);
        }

        public override string Getstatus(string ip)
        {
            string connectAddress = "http://" + ip;
            var _wr = WebRequest.Create(connectAddress) as HttpWebRequest;
            _wr.Timeout = 4000;
            _wr.KeepAlive = false;
            try
            {
                var resp = (HttpWebResponse)_wr.GetResponse();
                if (resp.StatusCode == HttpStatusCode.ServiceUnavailable)
                    return Errors.ERR_BEG + Errors.NO_CONNECTION;
                return Errors.NO_ERRORS;
            }
            catch (Exception)
            {
                return Errors.ERR_BEG + Errors.NO_CONNECTION;
            }
            //return "ok";
        }

        public override string Getparams(string ip)
        {
            return "err:" + Errors.NOT_IMPLEMENTED;
        }

        public override string Getlog(string ip, string logFilePath)
        {
            return "err:" + Errors.NOT_IMPLEMENTED;
        }

        public override string TrapHandle(string devName, byte[] serializedTrap, DateTime date)
        {
            return "ok";
        }

        public override string Flush()
        {
            return "ok";
        }
    }
}
